package com.zjitc.controller;

import com.zjitc.pojo.User;
import com.zjitc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * Created with IDEA
 * author:lhl
 * Date:2019/2/19 0019
 * Time:11:13
 */
@Controller
@RequestMapping(value = "/admin")
public class AdminController {
    @Autowired
    UserService userService;
    /**
     * 管理员登录
     * @param session
     * @return
     */
    @RequestMapping(value = "/login")
    public String login(String username,String password,HttpSession session){
        User user = userService.login(username, password, 100);
        if (user!=null){
            session.setAttribute("user",user);
            return "redirect:/admin/kefu";
        }
        return "/index";
    }

    /**
     * 管理员客服主页
     * @param model
     * @return
     */
    @RequestMapping(value = "/kefu")
    public String adminKefu(Model model){
        List<User> allGuest = userService.getAllGuest();
        model.addAttribute("guests",allGuest);
        return "/adminKefu";
    }
}
